package com.twu.library.domain.mapper;

import com.twu.library.domain.model.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookMapper {
   //
   @Insert(
           "INSERT INTO books (book_name, book_author, year_published, description, key_words) " +
                   "VALUES (#{name}, #{author}, #{yearPublished}, #{description}, #{keyWords})"
   )
   @Options(keyProperty = "bookId", useGeneratedKeys = true)
    public void insert(Book book);


    @Select(
            "SELECT book_id, book_name, book_author, year_published, description, key_words " +
                    "FROM books " +
                    "WHERE book_name = #{name}"
    )
    @Results(value = {
            @Result(property="id", column = "book_id"),
            @Result(property="name", column = "book_name"),
            @Result(property="author",column = "book_author"),
            @Result(property="yearPublished", column = "year_published"),
            @Result(property = "description", column = "description"),
            @Result(property="keyWord", column="key_word")
    })
    public List<Book> getTheBookByName(String name);

}
